﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataAccess;
using BusinessLogic;

namespace CarService
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Load_Info();
            if (!Page.IsPostBack)
            {
                Load_Slider();
                Load_Service();
                Load_News();
            }
        }

        #region Load Site Info
        private void Load_Info()
        {
            SettingInfo settingInfo = SettingData.SelectBySiteID(Config.Global.Settings.SiteID);
            Page.Title = settingInfo.SiteName + " - " + settingInfo.SiteURL;
            Page.MetaDescription = settingInfo.SiteDescription;
            Page.MetaKeywords = settingInfo.SiteKeyword;
        }
        #endregion

        #region Load_Slider
        private void Load_Slider()
        {
            DataSet dsSlider = new DataSet();
            dsSlider.ReadXml(Server.MapPath("App_Data/Slider.xml"));
            rptSlider.DataSource = dsSlider;
            rptSlider.DataBind();
        }
        #endregion

        #region Load Service
        private void Load_Service()
        {
            DataTable dtbService = ServiceData.SelectAll();
            if ((dtbService != null) && (dtbService.Rows.Count > 0))
            {
                rptService.DataSource = dtbService;
                rptService.DataBind();
            }
        }
        #endregion

        #region Load News
        private void Load_News()
        {
            NewsBusiness newsBusiness = new NewsBusiness();
            int topNewsID = newsBusiness.SelectNewNewsID(1);
            NewsInfo newsInfo = NewsData.SelectByNewsID(topNewsID);
            lblDesc.Text = newsInfo.NewsDescription;
            lblTitle.Text = newsInfo.NewsTitle;
            linkNews.NavigateUrl = "News.aspx?ID=" + newsInfo.NewsID;

            DataTable dtbNews = newsBusiness.SelectOtherNews(topNewsID, 3);
            if ((dtbNews != null) && (dtbNews.Rows.Count > 0))
            {
                rptNews.DataSource = dtbNews;
                rptNews.DataBind();
            }
        }
        #endregion
    }
}